const PENDING = 'pending'
const FULFILLED = 'fulfilled'
const REJECTED = 'rejected'

class MyPromise {
  #state = PENDING;
  #result = undefined;

  constructor(exe) {
    const resolve = (data) => {
      this.#changeState(FULFILLED, data)
    };
    const reject = (reason) => {
      this.#changeState(REJECTED, reason)
    };
    try {
      exe(resolve, reject)
    } catch (error) {
      reject(error)
    }
  }

  #changeState(state, result) {
    if (this.#state !== PENDING) return;
    this.#state = state
    this.#result = result
  }
}

const p = new MyPromise((reslove, reject) => {
  reslove(1)
})

console.log(p);
